package com.demo.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.DesensitizedUtil;
//import com.custom.starter.service.MailService;
import com.demo.utils.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;

/**
 * @author wangfengchen
 * @since 2021/9/1
 */
@RestController
@Slf4j
public class Test {

  @Autowired
  private RedisUtil redisUtil;
//  @Autowired
//  private MailService mailService;
  //    @Autowired
  //    private RedissonClient redissonClient;
  //
  //    private static final String CACHE_KEY = "number";
  //
  //    @GetMapping("/test")
  //    public boolean test() {
  //        String lockKey = "test";
  //        RLock lock = redissonClient.getLock(lockKey);
  //        try {
  //            lock.lock();
  //            String number = redisUtil.get(CACHE_KEY);
  //            if(Integer.parseInt(number) > 0){
  //                redisUtil.decrby(CACHE_KEY, 1);
  //            }
  //        }finally {
  //            lock.unlock();
  //        }
  ////        String number = redisUtil.get(CACHE_KEY);
  ////        if(Integer.parseInt(number) > 0){
  ////            redisUtil.decrby(CACHE_KEY, 1);
  ////        }
  //        return true;
  //    }

  @GetMapping("/test2")
  public boolean test2() {
    redisUtil.set("number", "1000");
    return true;
  }

//  @GetMapping("/sendMail")
//  public boolean sendMail() {
//    mailService.sendSimpleMailMessage("wang", "test");
//    return true;
//  }
//
//  @PostMapping("/sendMailFile")
//  public boolean sendMailFile(
//      @RequestParam(value = "files") MultipartFile[] files) {
//    mailService.sendMimeMessage("测试", "wang", files);
//    return true;
//  }

  public static void main(String[] args) {
    System.out.println(DateUtil.offsetDay(new Date(),  -7));
    System.out.println(DateUtil.beginOfDay(DateUtil.offsetDay(new Date(),  -7)));
    System.out.println(// 180****1999
        DesensitizedUtil.mobilePhone("18049531999"));
  }

}
